package mongodb

import (
	"GoServer/common"
	"GoServer/models"
	"GoServer/utils/debug"
	"context"
	"fmt"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

func CreateIndexes(database *mongo.Database) {
	//创建 anchor_info_basic 的索引（anchor_id 唯一）
	collection := database.Collection(common.GameName + models.AnchorCollection)

	index := mongo.IndexModel{
		Keys:    bson.D{{Key: "anchor_id", Value: 1}},
		Options: options.Index().SetUnique(true),
	}

	_, err := collection.Indexes().CreateOne(context.Background(), index)
	if err != nil {
		debug.Logf(debug.Error, fmt.Sprintf("创建 Anchor 索引失败: %v", err))
	}

	debug.Logln(debug.Info, "Anchor 索引创建完成")
}
